<?php
class ComponentsController extends XPHP_Controller
{
	public function footerAction()
	{
		//Lấy thông tin công ty
		$modelInfor = new Areas_Contacts_Models_Information();
		$modelLang = new Models_Language();
		$arrInfor = $modelInfor->db->where('lang_id', $_SESSION['lang_id'])
									->order_by('position', 'ASC')
									->get()
									->result();
		$arr = array();
		foreach( $arrInfor as $key=>$value)
		{
			$arr[$value->name] = $value->value;
		}
		$this->view->arrInfor = $arr;
		return $this->view();
	}
	
	public function chooseLangAction()
	{
		//Lấy danh sách ngôn ngữ
		$model = new Models_Language();
		$arrLang = $model->db->order_by('name', 'ASC')
						->get()
						->result();
		$this->view->arrLang = $arrLang;
		return $this->view();
	}
	
	public function chooseLangAJAX()
	{
		//Nhận lang code, url
		$model = new Models_Language();
		$this->session->clang = $this->params['langCode'];
		$this->session->lang_id = $model->getIdLang($this->params['langCode']);
		return $this->json(array('success' => true, 'url' => $this->params['url']));
	}
	
	public function topMenuAction()
	{
		return $this->view();
	}
	
	public function rightSideBarAction()
	{
		//Sidebar menu
		//Lấy danh sách hỗ trợ trực tuyến
		$modelGroup = new Models_SupportGroup();
		$modelSupport = new Models_OnlineSupport();
		$arrGroup = $modelGroup->db->order_by('name', 'ASC')->get()->result();
		$arrSupport = array();
		foreach ($arrGroup as $group)
		{
			//Lấy danh sách hỗ trợ thuộc nhóm
			$arr = $modelSupport->db->where('group_id', $group->id)
									->order_by('name', 'ASC')->get()->result();
			foreach ($arr as $support)
			{
				$arrSupport[$group->name][$support->id] = $support;
			}
		}
		$this->view->arrSupport = $arrSupport;
		//Lấy thông tin video
		return $this->view();
	}
	
    public function yahooStatusAJAX()
    {
    	$link = "http://opi.yahoo.com/online?u=".$this->params['yahooID']."&amp;m=a&amp";
		$status = @file($link);
		$status = implode("", $status);
		if(strripos($status, "NOT ONLINE"))
			return $this->json(array("id" => $this->params['yahooID'], "image" => $this->url->content("Content/VietTrung/img/offline.png")));
		elseif (strripos($status, "ONLINE"))
			return $this->json(array("id" => $this->params['yahooID'], "image" => $this->url->content("Content/VietTrung/img/online.png")));
		else 
			return $this->json(array("id" => $this->params['yahooID'], "image" => $this->url->content("Content/VietTrung/img/offline.png")));
    }
}